﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace ExpressionEvaluator.BuilderTreeNode
{
	/// <summary>
	/// Node containing expression in brackets.
	/// </summary>
	internal class BracketNode : BuilderTreeNodeBase
	{

		/// <summary>
		/// Gets or sets the start bracket.
		/// </summary>
		/// <value>The start bracket.</value>
		public CodeBlock StartBracket
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the end bracket.
		/// </summary>
		/// <value>The end bracket.</value>
		public CodeBlock EndBracket
		{
			get;
			set;
		}

		/// <summary>
		/// Gets the expression.
		/// </summary>
		/// <param name="tree">The tree.</param>
		/// <returns>Expression value of this node.</returns>
		public override Expression GetExpression(BuilderTree tree)
		{
			return Nodes[0].GetExpression(tree);
		}

		/// <summary>
		/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
		/// </summary>
		/// <returns>
		/// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
		/// </returns>
		public override string ToString()
		{
			if (Nodes.Count > 0)
			{
				string items = string.Empty;
				foreach (var node in Nodes)
				{
					if (items.Length > 0)
					{
						items += ", ";
					}
					items += node.ToString();
				}
				return "(" + items + ")";
			}
			return "()";
		}
	}
}
